package com.gl.controller;


import com.gl.entity.EduChapter;
import com.gl.entity.chapterOrVideo.Chapter;
import com.gl.service.EduChapterService;
import com.gl.utils.CommonResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2020-12-14
 */
@RestController
@RequestMapping("/chapter")
public class EduChapterController {

    @Autowired
    private EduChapterService chapterService;

    //根据课程id获取所有章节小节数据
    @GetMapping("getListByCourseId/{id}")
    public CommonResponse getListByCourseId(@PathVariable String id){
        List<Chapter> list = chapterService.getChapterVideoByCourseId(id);
        return CommonResponse.ok().data("list",list);
    }

    //添加章节
    @PostMapping("addChapter")
    public CommonResponse addChapter(@RequestBody EduChapter chapter){
        chapterService.save(chapter);
        return CommonResponse.ok();
    }


    //根据章节id查询章节信息
    @GetMapping("getInfoById/{id}")
    public CommonResponse getInfoById(@PathVariable String id){
        EduChapter chapter = chapterService.getById(id);
        return CommonResponse.ok().data("chapter",chapter);
    }

    //修改章节
    @PostMapping("updateChapter")
    public CommonResponse updateChapter(@RequestBody EduChapter chapter){
        chapterService.updateById(chapter);
        return CommonResponse.ok();
    }


}

